
import { _decorator, Component, Node, Collider, ITriggerEvent, ICollisionEvent, AudioClip } from 'cc';
const { ccclass, property , menu} = _decorator;

/**
 * Predefined variables
 * Name = NewComponent
 * DateTime = Wed Feb 16 2022 19:26:48 GMT+0800 (中国标准时间)
 * Author = ashscc
 * FileBasename = NewComponent.ts
 * FileBasenameNoExtension = NewComponent
 * URL = db://assets/script/NewComponent.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/en/
 *
 */
@ccclass('CollisionTest')
@menu('test/CollisionTest')
export class CollisionTest extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

    start () {
        const collider = this.getComponent(Collider)
        collider.on('onTriggerEnter', this._onTriggerEnter, this)
        collider.on('onTriggerStay', this._onTriggerStay, this)
        collider.on('onTriggerExit', this._onTriggerExit, this)
        collider.on('onCollisionEnter', this._onCollisionEnter, this)
        collider.on('onCollisionStay', this._onCollisionStay, this)
        collider.on('onCollisionExit', this._onCollisionExit, this)
    }

    private _onTriggerEnter(event: ITriggerEvent) {
        console.log(this.node.name + '    target  ' + event.otherCollider.node.name + ' type    ' + event.type)
    }

    private _onTriggerStay(event: ITriggerEvent) {
        console.log(this.node.name + '    target  ' + event.otherCollider.node.name + ' type    ' + event.type)
    }

    private _onTriggerExit(event: ITriggerEvent) {
        console.log(this.node.name + '    target  ' + event.otherCollider.node.name + ' type    ' + event.type)
    }

    private _onCollisionEnter(event: ICollisionEvent) {
        console.log(this.node.name + '    target  ' + event.otherCollider.node.name + ' type    ' + event.type)
    }

    private _onCollisionStay(event: ICollisionEvent) {
        console.log(this.node.name + '    target  ' + event.otherCollider.node.name + ' type    ' + event.type)
    }

    private _onCollisionExit(event: ICollisionEvent) {
        console.log(this.node.name + '    target  ' + event.otherCollider.node.name + ' type    ' + event.type)
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/en/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/en/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/en/scripting/life-cycle-callbacks.html
 */
